package com.noahplat.erp.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.erp.service.AlterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;

/**
 * 账套变更审核相关操作
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/3/1 9:22
 **/
@RestController
@RequestMapping("/api/alter")
@Validated
public class AlterController {

    @Autowired
    private AlterService alterService;

    /**
     * 用户申请信息
     *
     * @param acctid
     * @param alterType
     * @param uid
     * @return
     * @author 李东
     * @Date: 2021/3/1 9:22
     */
    @PreAuthorize("hasAuthority('noahplat-service-erp:AlterController:applyAlter')")
    @PostMapping("/applyAlter")
    public Result applyAccountAlterInfo(@NotEmpty(message = "账套Id不能为空") @RequestParam("acctid") String acctid, @NotEmpty(message = "变更类型不能为空") @RequestParam("alterType") String alterType, @Min(value = 1, message = "用户Id不能为空") @RequestParam("uid") Long uid) {
        return alterService.applyAlterInfo(acctid, alterType, uid);
    }


    /**
     * 审核人审核账套变更记录
     *
     * @param id
     * @param remark
     * @param status
     * @param uid
     * @return
     * @author 李东
     * @Date: 2021/3/1 9:22
     */
    @PreAuthorize("hasAuthority('noahplat-service-erp:AlterController:auditAlter')")
    @PostMapping("/auditAlter")
    public Result auditAlter(@NotEmpty(message = "参数id不能为空") String id, String remark, @NotEmpty(message = "参数status不能为空") String status, @Min(value = 1, message = "用户Id不能为空") Long uid) {
        return alterService.auditAlter(id, remark, status, uid);
    }

    /**
     * 通过账套id以及状态查询申请记录
     *
     * @param acctid
     * @param status
     * @param page
     * @param limit
     * @return
     * @author 李东
     * @Date: 2021/3/30 11:22
     */
    @PreAuthorize("hasAuthority('noahplat-service-erp:AlterController:findAlterList')")
    @GetMapping("/findAlterList")
    public Result findAlterList(@Min(value = 1, message = "账套不能为空") Long acctid, String status, @Min(value = 1, message = "page不能为空") Integer page, @Min(value = 10, message = "limit不能为空") Integer limit) {
        return alterService.findAlterList(acctid, status, page, limit);
    }

    /**
     * 解除绑定
     *
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-erp:AlterController:unbindAccount')")
    @PostMapping("/unbindAccount")
    public Result unbindAccount(@Min(value = 1, message = "账套不能为空") Long id) {
        return alterService.unbindAccount(id);
    }

}
